package com.biomatch.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.biomatch.domain.CardType;
import com.biomatch.domain.Type;
import com.biomatch.dto.Pagination;
import com.biomatch.response.RestResponse;
import com.biomatch.response.RestResult;
import com.biomatch.service.CardTypeService;
import com.biomatch.service.DanceTypeService;
import com.biomatch.utils.Internationalize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("dance.cardType")
@RequestMapping("/cardType")
@Api(value = "课卡类型管理")
public class CardTypeController {

    @Autowired
    private CardTypeService cardTypeService;

    @Autowired
    private Internationalize internationalize;


    @RequestMapping(value="/getAllTypeByPage", method = RequestMethod.POST)
    @ApiOperation(value = "分页获取位置", response = CardType.class, httpMethod = "POST")
    public RestResult<CardType> getAllTypeByPage(@RequestBody Pagination pagination) {
        IPage<CardType> result=cardTypeService.getAllTypeByPage(pagination);
        return RestResponse.success(result);
    }

    @RequestMapping(value="/getAll", method = RequestMethod.POST)
    @ApiOperation(value = "获取全部", response = CardType.class, httpMethod = "POST")
    public RestResult<List<CardType>> getAll() {
        List<CardType> result =cardTypeService.getAll();
        return RestResponse.success(result);
    }

    @RequestMapping(value="/saveOrUpdate", method = RequestMethod.POST)
    @ApiOperation(value = "新增或更新", response = CardType.class, httpMethod = "POST")
    public RestResult<CardType> saveOrUpdate(@RequestBody CardType cardType) {
        CardType result = cardTypeService.saveOrUpdate(cardType);
        if (result == null) {
            return RestResponse.error(internationalize.getMessage("position.name.repeat"));
        } else {
            return RestResponse.success(result);
        }
    }

    @RequestMapping(value="/delete", method = RequestMethod.POST)
    @ApiOperation(value = "删除", response = CardType.class, httpMethod = "POST")
    public RestResult<CardType> delete(@RequestBody CardType cardType ) {
        CardType result = cardTypeService.delete(cardType);
        if (result == null) {
            return RestResponse.error(internationalize.getMessage("position.status.used"));
        } else {
            return RestResponse.success(result);
        }
    }
}

